#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDebug>
#include <QFile>
#include <sqliteoperator.h>
#include <QFileDialog>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
    , ui(new Ui::MainWindow)
{
    ui->setupUi(this);
    QApplication * pApp = (QApplication*)QApplication::instance();

    pMusicWindow = new musicWindow;//实例化音乐播放窗口

    QPixmap pm;
    bool ret = pm.load("C:/Users/lygamer/Desktop/untitled3/1.jpg");
    if(ret == false)
    {
        qDebug()<<"加载图片失败";
    }
    else
    {
        ui->label_2->setPixmap(pm);
        ui->label_2->setScaledContents(true);
        ui->label_2->setPurpose(set_image);
    }
    QPixmap pm1;
    bool ret1 = pm1.load("C:/Users/lygamer/Desktop/untitled9/close.png");
    ui->label->setPixmap(pm1);
    ui->label->setScaledContents(true);
    ui->label->setPurpose(close_window);

    this->setWindowFlag(Qt::FramelessWindowHint);//设置窗口为无边框
    this->setAttribute(Qt::WA_TranslucentBackground);//把窗口设置为透明

//    ui->centralwidget->setStyleSheet("background-color: rgb(255, 255, 255); border-radius: 15px;");

    QFile file(":/test.qss");
    file.open(QIODevice::ReadOnly);
    pApp->setStyleSheet(file.readAll());
    file.close();
    connect(ui->label,SIGNAL(closeWindow()),this,SLOT(on_pushButton_2_clicked()));
    connect(ui->label_2,SIGNAL(setImage()),this,SLOT(setImage()));

}

MainWindow::~MainWindow()
{
    delete ui;
}

//this->setWindowFlag(Qt::FramelessWindowHint);
//setAttribute(Qt::WA_TranslucentBackground);//设置窗口透明化


void MainWindow::on_pushButton_2_clicked()
{
    close();
}

void MainWindow::setImage()
{
    QString fileName = QFileDialog::getOpenFileName(this,
        tr("Open Image"), "./", tr("Image Files (*.png *.jpg *.bmp)"));
    QPixmap pm;
    bool ret = pm.load(fileName);
    if(ret == false)
    {
        qDebug()<<"加载图片失败";
    }
    else
    {
        ui->label_2->setPixmap(pm);
        ui->label_2->setScaledContents(true);
    }
}

void MainWindow::on_pushButton_clicked()
{
    pMusicWindow->setComebackWindow(this);
    pMusicWindow->show();
    this->hide();
}
